package com.wyq.new_springboot.util.result;

/**
 * 接口结果生成器
 * @author wyq on 2021/3/28.
 */
public class ResultGenerator {
    /**
     * 默认的成功返回（无data）
     * @return
     */
    public static Result genSuccessResult(){
      return Result.ResultBuilder.aResult()
              .withCode(ResultCode.SUCCESS.getCode())
              .withMessage(ResultMessage.SUCCESS.getMessage()).build();
    }
    public static Result genSuccessResult(Object data){
        return Result.ResultBuilder.aResult()
                .withMessage(ResultMessage.SUCCESS.getMessage())
                .withCode(ResultCode.SUCCESS.getCode())
                .withData(data).build();
    }

    /**
     * 失败结果
     * @param message
     * @return
     */
    public static Result genFailResult(ResultCode code,String message) {//自定义的错误码
        return Result.ResultBuilder.aResult()
                .withCode(code.getCode())
                .withMessage(message).build();

    }
}
